import ACCESS_ENUM from "../access/accessEnum";
import { UserControllerService } from "@/service";

const actions = {
  async getCurrentUser({ commit, state }: any) {
    const res = await UserControllerService.currentUserVo();
    if (res.code === 0) {
      commit("updateLoginUser", res.data);
    } else {
      commit("updateLoginUser", {
        ...state.loginUser,
        userRole: ACCESS_ENUM.NOT_LOGIN,
      });
    }
  },
};
const state = () => ({
  loginUser: {
    userName: "未登录",
    userRole: ACCESS_ENUM.NOT_LOGIN,
  },
});
const mutations = {
  updateLoginUser(state: any, payload: any) {
    state.loginUser = {
      userName: payload.userName,
      userRole: payload.userRole,
    };
  },
};
export default {
  namespace: true,
  state,
  mutations,
  actions,
};
